package com.xiaoluo.lottery.common.asyn;

import com.xiaoluo.lottery.common.utils.ApplicationContextUtil;
import com.xiaoluo.lottery.common.weixin.base.IPaidCallBack;
import com.xiaoluo.lottery.entity.Order;
import com.xiaoluo.lottery.exception.LotteryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Project : XL-CD
 * Package : com.xiaoluo.common.queue
 * Created by Willian.
 * Date  : 2016/1/6 20:51.
 */
public class Worker implements Runnable{
    private final static Logger logger = LoggerFactory.getLogger(Worker.class);

    private Order obj;

    public Worker(Order obj){
        super();
        this.obj = obj;
    }

    @Override
    public void run() {
        try {
            logger.info("call back orderNode:{}",obj.getOrderNo());
            //IPaidCallBack callBack = (IPaidCallBack)ApplicationContextUtil.context.getBean(IPaidCallBack.class.getName());
            IPaidCallBack callBack = (IPaidCallBack) ApplicationContextUtil.context.getBean(Class.forName(obj.getCbClass()));
            //Class<IPaidCallBack> callBack = (Class<IPaidCallBack>) Class.forName(order.getCbClass());
            callBack.process(obj);
        } catch (Exception e) {
            if(e instanceof LotteryException){
                LotteryException le=(LotteryException)e;
                logger.error("doCallBack LotteryException:{}",le.getError());
            }else{
                e.printStackTrace();
                logger.error("doCallBack OtherException:",e);
            }

        }
    }
}
